package com.sec.android.app.myfiles.module.local.recent;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;

import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.provider.DbTableInfo;

import org.puremvc.java.multicore.interfaces.INotification;
import org.puremvc.java.multicore.patterns.command.SimpleCommand;

public class ClearRecentCmd extends SimpleCommand {
    @Override
    public void execute(INotification notification) {
        Object[] params = (Object[]) notification.getBody();
        Context context = (Context) params[0];
        if (context != null) {
            ContentResolver cr = context.getContentResolver();
            DbTableInfo tableInfo = DbTableInfo.getInstance(FileRecord.StorageType.Recent);
            if (tableInfo != null) {
                Uri uri = Uri.parse(tableInfo.getUri());
                if (cr.delete(uri, null, null) > 0) {
                    Log.d(this, "all recent history are removed.");
                } else {
                    Log.d(this, "Failed to remove all recent history.");
                }
            }
        }
    }
}
